#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //窗体最小宽度高度
    setMinimumSize(280,150);
    setMaximumSize(280,150);
    //实例用户名密码控件
    usrLabel=new QLabel(QString::fromUtf8("用户名:"));
    pwdLabel=new QLabel(QString::fromUtf8("密  码："));
    //
    usrLineEdit=new QLineEdit();
    pwdLineEdit=new QLineEdit();
    //密码*号输入
    pwdLineEdit->setEchoMode(QLineEdit::Password);
    //限制12位
    usrLineEdit->setMaxLength(12);
    pwdLineEdit->setMaxLength(12);
    //实例网格布局控件
    gridLayout=new QGridLayout();
    //添加布局0,0,1,1行 列 行间距 列间距

    gridLayout->addWidget(usrLabel,0,0,1,1);
    gridLayout->addWidget(usrLineEdit,0,1,1,1);
    //间隔
    gridLayout->setSpacing(20);
    //
    gridLayout->addWidget(pwdLabel,1,0,1,1);
    gridLayout->addWidget(pwdLineEdit,1,1,1,1);
    //实例按钮控件
    okBtn=new QPushButton(QString::fromUtf8("确定"));
    cancelBtn=new QPushButton(QString::fromUtf8("取消"));
    //
    connect(okBtn,
            SIGNAL(clicked(bool)),
            this,
            SLOT(accept())
                );
    //
    connect(cancelBtn,SIGNAL(clicked(bool)),
            this,
            SLOT(reject())
            );
    //
    QHBoxLayout * hboxLayout=new QHBoxLayout();
    hboxLayout->setSpacing(60);
    //横向布局填充控件
    hboxLayout->addWidget(okBtn);
    hboxLayout->addWidget(cancelBtn);
    //实例纵向布局填充刚刚实例的2个布局
    vboxLayout=new QVBoxLayout();
    vboxLayout->addLayout(gridLayout);
    vboxLayout->addLayout(hboxLayout);
    //显示内容
    this->setLayout(vboxLayout);
    //




}
void  MainWindow::accept()
{
    if(usrLineEdit->text().trimmed()=="admin"
            &&pwdLineEdit->text().trimmed()=="admin")
    {
        QDialog::accept();
    }
    else{
        QMessageBox::warning(this,
                             QString::fromUtf8("警告"),
                             QString::fromUtf8("用户或密码错误！！"),
                             QMessageBox::Yes);
        usrLineEdit->setFocus();
    }
}
MainWindow::~MainWindow()
{
    delete ui;
}
